﻿<UserControl x:Class="Apps.Yunwei.RolesWidget"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Apps.Yunwei.ViewModels"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
	         xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
             xmlns:dataPrimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
             xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">
    <UserControl.Resources>
        <local:Counter x:Key="CounterDataSource" Timeout="1000" Increment="100"/>
        <Style TargetType="data:DataGridRow">
            <Setter Property="IsTabStop" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="data:DataGridRow">
                        <dataPrimitives:DataGridFrozenGrid x:Name="Root" Height="31" Background="#19000000" RenderTransformOrigin="0.5,0.5">
                            <dataPrimitives:DataGridFrozenGrid.Resources>
                                <Storyboard x:Key="DetailsVisibleTransition">
                                    <DoubleAnimation Duration="00:00:0.1" Storyboard.TargetProperty="ContentHeight" Storyboard.TargetName="DetailsPresenter"/>
                                </Storyboard>
                            </dataPrimitives:DataGridFrozenGrid.Resources>
                            <dataPrimitives:DataGridFrozenGrid.Projection>
                                <PlaneProjection/>
                            </dataPrimitives:DataGridFrozenGrid.Projection>
                            <dataPrimitives:DataGridFrozenGrid.RenderTransform>
                                <CompositeTransform/>
                            </dataPrimitives:DataGridFrozenGrid.RenderTransform>
                            <dataPrimitives:DataGridFrozenGrid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="0.773*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </dataPrimitives:DataGridFrozenGrid.ColumnDefinitions>
                            <dataPrimitives:DataGridFrozenGrid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </dataPrimitives:DataGridFrozenGrid.RowDefinitions>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualStateGroup.Transitions>
                                        <VisualTransition GeneratedDuration="0:0:0.2">
                                            <VisualTransition.GeneratedEasingFunction>
                                                <CubicEase EasingMode="EaseInOut"/>
                                            </VisualTransition.GeneratedEasingFunction>
                                        </VisualTransition>
                                    </VisualStateGroup.Transitions>
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="NormalAlternatingRow">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundRectangle"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundRectangle"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="NormalSelected">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundRectangle"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="MouseOverSelected">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundRectangle"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="UnfocusedSelected">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundRectangle"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="NormalEditing"/>
                                    <VisualState x:Name="UnfocusedEditing"/>
                                    <VisualState x:Name="MouseOverUnfocusedEditing"/>
                                    <VisualState x:Name="MouseOverEditing"/>
                                    <VisualState x:Name="MouseOverUnfocusedSelected"/>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="ValidationStates">
                                    <VisualState x:Name="Valid"/>
                                    <VisualState x:Name="Invalid">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="BackgroundRectangle">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                            </ObjectAnimationUsingKeyFrames>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="InvalidVisualElement"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="RowStates">
                                    <VisualStateGroup.Transitions>
                                        <VisualTransition GeneratedDuration="0:0:0.2" To="Show">
                                            <VisualTransition.GeneratedEasingFunction>
                                                <CircleEase EasingMode="EaseInOut"/>
                                            </VisualTransition.GeneratedEasingFunction>
                                            <Storyboard>
                                                <DoubleAnimation Duration="0:0:0.4" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Root">
                                                    <DoubleAnimation.EasingFunction>
                                                        <CubicEase EasingMode="EaseInOut"/>
                                                    </DoubleAnimation.EasingFunction>
                                                </DoubleAnimation>
                                                <DoubleAnimation Duration="0:0:0.266" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="BackgroundRectangle">
                                                    <DoubleAnimation.EasingFunction>
                                                        <CubicEase EasingMode="EaseIn"/>
                                                    </DoubleAnimation.EasingFunction>
                                                </DoubleAnimation>
                                                <DoubleAnimation Duration="0:0:0.266" To="1" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="Root">
                                                    <DoubleAnimation.EasingFunction>
                                                        <CubicEase EasingMode="EaseIn"/>
                                                    </DoubleAnimation.EasingFunction>
                                                </DoubleAnimation>
                                                <DoubleAnimation Duration="0:0:0.266" To="1" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="Root">
                                                    <DoubleAnimation.EasingFunction>
                                                        <CubicEase EasingMode="EaseIn"/>
                                                    </DoubleAnimation.EasingFunction>
                                                </DoubleAnimation>
                                            </Storyboard>
                                        </VisualTransition>
                                    </VisualStateGroup.Transitions>
                                    <VisualState x:Name="Prepare">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Root"/>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="BackgroundRectangle"/>
                                            <DoubleAnimation Duration="0" To="-89" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationX)" Storyboard.TargetName="Root"/>
                                            <DoubleAnimation Duration="0" To="-134" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.GlobalOffsetZ)" Storyboard.TargetName="Root"/>
                                            <DoubleAnimation Duration="0" To="0.95" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="Root"/>
                                            <DoubleAnimation Duration="0" To="0.95" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="Root"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Show">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Root"/>
                                            <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="BackgroundRectangle"/>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="Root"/>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="Root"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <i:Interaction.Triggers>
                                <ei:TimerTrigger MillisecondsPerTick="{Binding Count, Mode=OneWay, Source={StaticResource CounterDataSource}}">
                                    <ei:GoToStateAction StateName="Show"/>
                                </ei:TimerTrigger>
                                <i:EventTrigger EventName="Loaded">
                                    <ei:GoToStateAction StateName="Prepare" UseTransitions="False"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                            <Rectangle x:Name="BackgroundRectangle" Grid.ColumnSpan="3" Fill="{StaticResource TileBrush}" Opacity="0" Grid.RowSpan="1" Grid.Column="1" RenderTransformOrigin="0.5,0.5">
                                <Rectangle.RenderTransform>
                                    <CompositeTransform/>
                                </Rectangle.RenderTransform>
                            </Rectangle>
                            <Rectangle x:Name="InvalidVisualElement" Grid.ColumnSpan="3" Fill="#FFF7D8DB" Opacity="0" Grid.RowSpan="1" Grid.Column="1"/>
                            <dataPrimitives:DataGridRowHeader x:Name="RowHeader" dataPrimitives:DataGridFrozenGrid.IsFrozen="True" Grid.RowSpan="1" Grid.Column="1"/>
                            <dataPrimitives:DataGridCellsPresenter x:Name="CellsPresenter" Grid.Column="1" dataPrimitives:DataGridFrozenGrid.IsFrozen="True" Grid.ColumnSpan="3"/>
                            <dataPrimitives:DataGridDetailsPresenter x:Name="DetailsPresenter" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="3"/>
                            <Rectangle x:Name="BottomGridLine" Grid.Column="1" HorizontalAlignment="Stretch" Height="1" Grid.Row="2" Grid.ColumnSpan="3" Margin="0,0,0,-1"/>
                            <StackPanel Grid.Column="1" HorizontalAlignment="Right" Margin="0,1,4,1" Orientation="Horizontal">
                                <Button x:Name="edit" Content="Edit" HorizontalAlignment="Center" 
                                        VerticalAlignment="Center" 
                                        Command="{Binding DataContext.EditCommand, Mode=OneWay,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}}"
                                        CommandParameter="{Binding Mode=OneWay}" Style="{StaticResource Edit-Button}" Width="26"/>
                                <Button x:Name="delete" Content="Delete" Margin="4,0" 
                                        HorizontalAlignment="Center" VerticalAlignment="Center"
                                        Command="{Binding DataContext.DeleteCommand, Mode=OneWay,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}}"
                                        CommandParameter="{Binding Mode=OneWay}" Style="{StaticResource Delete-Button}" Width="15"/>
                            </StackPanel>
                        </dataPrimitives:DataGridFrozenGrid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <UserControl.DataContext>
        <local:RolesViewModel/>
    </UserControl.DataContext>
    <Grid x:Name="LayoutRoot">
        <data:DataGrid x:Name="MainDataGrid" Margin="1" ItemsSource="{Binding Items}">
            <data:DataGrid.Columns>
                <data:DataGridTextColumn Binding="{Binding Code}" Header="编码" Width="0.1*"/>
                <data:DataGridTextColumn Binding="{Binding Caption}" Header="名称" Width="0.15*"/>
                <data:DataGridTextColumn Binding="{Binding Describe}" Header="描述" Width="0.35*"/>
            </data:DataGrid.Columns>
        </data:DataGrid>
        <Button Content="Add" HorizontalAlignment="Right"
                Command="{Binding AddCommand}"
                Style="{StaticResource AddNew-Button}"
                Margin="0,6,16,0" Width="19" Height="19" Grid.Row="2" VerticalAlignment="Top"/>
    </Grid>
</UserControl>